<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>推送信息</title>
    <link rel="stylesheet" type="text/css" href="/static/plugins/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/static/plugins/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/static/plugins/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/static/plugins/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="/static/admin/css/style.css" />

    <script type="text/javascript" src="/static/plugins/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="/static/plugins/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="/static/plugins/h-ui/js/H-ui.js"></script>
    <script type="text/javascript" src="/static/plugins/h-ui.admin/js/H-ui.admin.page.js"></script>
    <script type="text/javascript" src="/static/admin/js/myfun.js"></script>
</head>

<body>
    <div class="Hui-article">
        <form action="" method="post"  class="form form-horizontal" id="form-admin-save">
            <input type="hidden" id="aids" name="aids" value="{$aids}">
            <div class="ml-50">
                <p>所选文章id: <span class="c-red">{$aids}</span></p>
            </div>
            <div class="ml-50" style="width: 80%;">
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-4">专题所属分类</label>
                    <div class="formControls col-xs-8 col-sm-6">
                        <span class="select-box">
                            <select class="select" id="tcid" name="tcid">
                                <option value="0">所有类别</option>
                                {foreach $tclist as $value}
                                <option value="{$value.id}">{$value.name}</option>
                                {notempty name="value.child"}
                                {foreach $value.child as $val}
                                <option value="{$val.id}">--{$val.name}</option>
                                {/foreach}
                                {/notempty}
                                {/foreach}
                            </select>
                        </span>
                    </div>

                </div>
                <div class="row cl mt-20">
                    <label class="form-label col-xs-4 col-sm-4">所属专题</label>
                    <div class="formControls col-xs-8 col-sm-6">
                        <span class="select-box">
                            <select class="select" id="tid" name="tid">
                                <option value="0">所有专题</option>
                            </select>
                        </span>
                    </div>
                </div>
                <div class="row cl mt-20">
                    <label class="form-label col-xs-4 col-sm-4">子专题</label>
                    <div class="formControls col-xs-8 col-sm-6">
                        <span class="select-box">
                            <select class="select" id="tsid" name="tsid">
                                <option value="0">不属于子专题</option>
                            </select>
                        </span>
                    </div>
                </div>
                <div class="row cl mt-20">
                    <div class="row cl">
                        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                            <button type="button" class="btn btn-success radius" id="form-save" name="">推送至专题</button>
                            <button type="button" class="btn btn-default radius" onclick="layer_close()"
                                style="margin-left:20px;">取&nbsp;消</button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>

    <script>
        $(document).ready(function () {
            getTopicList(0);
        })


        $("#tcid").change(function () {
            var tcid = $("#tcid").val();

            getTopicList(tcid);
        })

        $("#tid").change(function () {
            var tid = $("#tid").val();

            getTopicSun(tid);
        })

        function getTopicList(tcid) {
            tcid = tcid || 0
            $.ajax({
                url: '/admin/topic_content/tlist?tcid=' + tcid,
                type: 'post',
                data: {},
                dataType: 'json',
                success: function (res) {
                    // console.log(res);
                    var listHmtl = "<option value='0'>所有专题</option>"

                    res.list.forEach(val => {
                        listHmtl += "<option value='" + val.id + "'>" + val.title + "</option>";
                    });

                    $("#tid").html(listHmtl);
                },
                error: function (res) {
                    layer.msg(res.msg, {
                        icon: 5,
                        time: 1000
                    });
                    return false;
                }
            })
        }

        function getTopicSun(tid) {
            if (tid==0) {
                layer.msg("专题id不可为空", {
                    icon: 5,
                    time: 1000
                });
                return false;
            }
            $.ajax({
                url: '/admin/topic_sun/tslist?tid=' + tid,
                type: 'post',
                data: {},
                dataType: 'json',
                success: function (res) {
                    // console.log(res);
                    var listHmtl = "<option value='0'>不属于子专题</option>"

                    res.list.forEach(val => {
                        listHmtl += "<option value='" + val.id + "'>" + val.title + "</option>";
                    });

                    $("#tsid").html(listHmtl);
                },
                error: function (res) {
                    layer.msg(res.msg, {
                        icon: 5,
                        time: 1000
                    });
                    return false;
                }
            })
        }

        $("#form-save").click(function () {
            var aids = $("#aids").val();
            var tid = $("#tid").val();
            var tsid = $("#tsid").val();

            // console.log(aids, tid, tsid);
            if (tid==0) {
                layer.msg("专题id不可为空", {
                    icon: 5,
                    time: 1000
                });
                return false;
            }

            $.ajax({
                url: '{:url("topic_info/saveaid")}',
                type: "post",
                data: {
                    'aids': aids,
                    'tid': tid,
                    'tsid': tsid
                },
                dataType: 'json',
                success: function (res) {
                    // console.log(res);
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 1000
                    }, function () {
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                    });
                },
                error: function (res) {
                    layer.msg(res.msg, {
                        icon: 5,
                        time: 1000
                    });
                    return false;
                }
            });

        })
    </script>
</body>

</html>